package com.slg.android.listenbook.biz.bookcity.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.slg.android.listenbook.R;
import com.slg.android.listenbook.biz.bookcity.model.CategoryDetail;

import java.util.List;

/**
 * Created by Darker on 2015/3/24.
 */
public class CategoryDetailAdapter extends BaseAdapter {

    private Context context;
    private List<CategoryDetail> data;

    public CategoryDetailAdapter(Context context,List<CategoryDetail> data){
        this.context = context;
        this.data = data;
    }
    @Override
    public int getCount() {
        int ret = 0;
        if(data != null){
            ret = data.size();
        }
        return ret;
    }

    @Override
    public Object getItem(int position) {
        return position;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        CategoryDetail categoryDetail = data.get(position);
        if(convertView == null){
            convertView = LayoutInflater.from(context).inflate(R.layout.item_category_detail_activity,
                    parent,false);
        }
        ViewHolder holder = (ViewHolder)convertView.getTag();
        if(holder==null){
           holder = new ViewHolder();
           convertView.setTag(holder);
        }
        holder.name = (TextView)convertView.findViewById(R.id.item_category_activity_name);
        holder.img = (ImageView)convertView.findViewById(R.id.item_category_activity_img);

        holder = (ViewHolder) convertView.getTag();
        holder.img.setImageResource(R.drawable.image_note_ds);
        holder.name.setText(categoryDetail.getName());

        return convertView;
    }

    public static class ViewHolder{
        public TextView name;
        public ImageView img;
    }
}
